﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

namespace Paas.Infrastructure.Data.Migrations
{
    public partial class NavigatProperty : Migration
    {
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.AlterColumn<Guid>(
                name: "MetaTableId",
                table: "MetaView",
                type: "uniqueidentifier",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)",
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "MetaSearchFormId",
                table: "MetaView",
                type: "uniqueidentifier",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)",
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "MetaAddButtonFormId",
                table: "MetaView",
                type: "uniqueidentifier",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)",
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "MetaTableId",
                table: "MetaTableField",
                type: "uniqueidentifier",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)",
                oldNullable: true);

            migrationBuilder.AlterColumn<Guid>(
                name: "MetaFieldId",
                table: "MetaTableField",
                type: "uniqueidentifier",
                nullable: true,
                oldClrType: typeof(string),
                oldType: "nvarchar(max)",
                oldNullable: true);

            migrationBuilder.CreateIndex(
                name: "IX_MetaView_MetaAddButtonFormId",
                table: "MetaView",
                column: "MetaAddButtonFormId");

            migrationBuilder.CreateIndex(
                name: "IX_MetaView_MetaSearchFormId",
                table: "MetaView",
                column: "MetaSearchFormId");

            migrationBuilder.CreateIndex(
                name: "IX_MetaView_MetaTableId",
                table: "MetaView",
                column: "MetaTableId");

            migrationBuilder.CreateIndex(
                name: "IX_MetaTableField_MetaFieldId",
                table: "MetaTableField",
                column: "MetaFieldId");

            migrationBuilder.CreateIndex(
                name: "IX_MetaTableField_MetaTableId",
                table: "MetaTableField",
                column: "MetaTableId");

            migrationBuilder.AddForeignKey(
                name: "FK_MetaTableField_MetaField_MetaFieldId",
                table: "MetaTableField",
                column: "MetaFieldId",
                principalTable: "MetaField",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_MetaTableField_MetaTable_MetaTableId",
                table: "MetaTableField",
                column: "MetaTableId",
                principalTable: "MetaTable",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_MetaView_MetaForm_MetaAddButtonFormId",
                table: "MetaView",
                column: "MetaAddButtonFormId",
                principalTable: "MetaForm",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_MetaView_MetaForm_MetaSearchFormId",
                table: "MetaView",
                column: "MetaSearchFormId",
                principalTable: "MetaForm",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);

            migrationBuilder.AddForeignKey(
                name: "FK_MetaView_MetaTable_MetaTableId",
                table: "MetaView",
                column: "MetaTableId",
                principalTable: "MetaTable",
                principalColumn: "Id",
                onDelete: ReferentialAction.Restrict);
        }

        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MetaTableField_MetaField_MetaFieldId",
                table: "MetaTableField");

            migrationBuilder.DropForeignKey(
                name: "FK_MetaTableField_MetaTable_MetaTableId",
                table: "MetaTableField");

            migrationBuilder.DropForeignKey(
                name: "FK_MetaView_MetaForm_MetaAddButtonFormId",
                table: "MetaView");

            migrationBuilder.DropForeignKey(
                name: "FK_MetaView_MetaForm_MetaSearchFormId",
                table: "MetaView");

            migrationBuilder.DropForeignKey(
                name: "FK_MetaView_MetaTable_MetaTableId",
                table: "MetaView");

            migrationBuilder.DropIndex(
                name: "IX_MetaView_MetaAddButtonFormId",
                table: "MetaView");

            migrationBuilder.DropIndex(
                name: "IX_MetaView_MetaSearchFormId",
                table: "MetaView");

            migrationBuilder.DropIndex(
                name: "IX_MetaView_MetaTableId",
                table: "MetaView");

            migrationBuilder.DropIndex(
                name: "IX_MetaTableField_MetaFieldId",
                table: "MetaTableField");

            migrationBuilder.DropIndex(
                name: "IX_MetaTableField_MetaTableId",
                table: "MetaTableField");

            migrationBuilder.AlterColumn<string>(
                name: "MetaTableId",
                table: "MetaView",
                type: "nvarchar(max)",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "MetaSearchFormId",
                table: "MetaView",
                type: "nvarchar(max)",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "MetaAddButtonFormId",
                table: "MetaView",
                type: "nvarchar(max)",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "MetaTableId",
                table: "MetaTableField",
                type: "nvarchar(max)",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldNullable: true);

            migrationBuilder.AlterColumn<string>(
                name: "MetaFieldId",
                table: "MetaTableField",
                type: "nvarchar(max)",
                nullable: true,
                oldClrType: typeof(Guid),
                oldType: "uniqueidentifier",
                oldNullable: true);
        }
    }
}
